package com.jonniespratley.codegen.view.templates
{
	import flash.net.NetConnection;
	import flash.net.Responder;

	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.utils.ArrayUtil;

	public class TestSchemaService
	{

		private var _connection:NetConnection;
		private var _gateway:String;
		static private var _data:ArrayCollection;

		public function TestSchemaService( gateway:String = '' )
		{
			_connection = new NetConnection();
			_connection.connect( gateway );
		}

		public function call( service:String, args:Array ):void
		{
			_connection.call( service, new Responder( onResult, onFault ), args.toString() );
		}

		public function onResult( eventObj:Object ):void
		{
			setData( new ArrayCollection( ArrayUtil.toArray( eventObj ) ) );
		}


		static public function getData():ArrayCollection
		{
			if ( _data == null )
			{
				_data = new ArrayCollection;
			}
			return _data;
		}


		static public function setData( value:ArrayCollection ):void
		{
			TestSchemaService._data = value;
		}


		public function getGateway():String
		{
			return _gateway;
		}

		public function setGateway( url:String ):void
		{
			this._gateway = url;
		}

		public function getConnection():NetConnection
		{
			return _connection;
		}

		public function setConnection( conn:NetConnection ):void
		{
			this._connection = conn;
		}


		private function onFault( faultObj:Object ):void
		{
			var faultEvent:FaultEvent = faultObj as FaultEvent;

  
		}
	}
}